package org.cwnuit.course.dao;

import java.sql.SQLException;
import java.util.List;

import org.cwnuit.course.domain.Classroom;
import org.cwnuit.course.util.IbatisSqlConfig;

import com.ibatis.sqlmap.client.SqlMapClient;

/**
 * 教室管理DAO
 * @author john
 */
public class ClassroomDAO{
	
	/**
	 * 根据教室ID获取教室信息
	 * @param roomid
	 * @return
	 */
	public Classroom getClassroom(Integer roomid) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		Classroom classroom = null;
		try {
			classroom = (Classroom) sqlMap.queryForObject("Classroom.getClassroom",roomid);
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return classroom;
	}

	/**
	 * 获取全部教室信息
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<Classroom> listClassroom() {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		List<Classroom> classroomList = null;
		try {
			classroomList = (List<Classroom>) sqlMap.queryForList("Classroom.listClassroom");
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return classroomList;
	}
	
	/**
	 * 添加教室信息
	 * @param Classroom
	 * @return
	 */
	public boolean insertClassroom(Classroom classroom) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.insert("Classroom.insertClassroom", classroom);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 更新教室信息
	 * @param Classroom
	 * @return
	 */
	public boolean updateClassroom(Classroom classroom) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.update("Classroom.updateClassroom",classroom);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
	
	/**
	 * 删除教室信息
	 * @param objectid
	 * @return
	 */
	public boolean deleteClassroom(Classroom classroom) {
		SqlMapClient sqlMap = IbatisSqlConfig.getSqlMapInstance();
		try {
			sqlMap.delete("Classroom.deleteClassroom", classroom);
			return true;
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return false;
	}
}
